<?php
namespace app\admin\controller;

use app\admin\controller\Base;
use think\Db;

class Index extends Base{

    /**
     * 后台首页
     * @return mixed
     */
    public function Index(){

        //获取昨日起始时间戳和结束时间戳
        $BeginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
        $EndYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;

        //获取本月起始时间戳和结束时间戳
        $BeginThismonth=mktime(0,0,0,date('m'),1,date('Y'));
        $EndThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'));

        //昨日新增用户数量
        $UserMap['add_time'] = array(array('egt',$BeginYesterday),array('lt',$EndYesterday));
        $UserCountYesterday = UserCount($UserMap);
        $this->assign('UserCountYesterday',$UserCountYesterday);

        //总用户数量
        $UserCount = UserCount(['id'=>array('gt',1)]);
        $this->assign('UserCount',$UserCount);

        //昨日新增收入
        $TotalIncomeYesterdayMap['add_time'] = array(array('egt',$BeginYesterday),array('lt',$EndYesterday));
        $TotalIncomeYesterdayMap['status'] = array('gt',0);
        $TotalIncomeYesterday = Db::name('user_order')->where($TotalIncomeYesterdayMap)->sum('pay_amount');
        $this->assign('TotalIncomeYesterday',$TotalIncomeYesterday);


        //总计收入
        $TotalIncomeMap['status'] = array('gt',0);
        $TotalIncome =  Db::name('user_order')->where($TotalIncomeMap)->sum('pay_amount');
        $this->assign('TotalIncome',$TotalIncome);


        //昨日奖金
        $FinanceMap['add_time'] = array(array('egt',$BeginYesterday),array('lt',$EndYesterday));
//        $FinanceMap['reward_type'] = array('in','3,4,5,11');
        $FinanceMap['reward_type'] = array('gt','10');
        $FinanceMap['type'] = 4;
        $FinanceYesterday = Db::name('finance')->where($FinanceMap)->sum('num');
        $this->assign('FinanceYesterday',$FinanceYesterday);

        //本月奖金
        $FinanceMothMap['add_time'] = array(array('egt',$BeginThismonth),array('lt',$EndThismonth));
//        $FinanceMothMap['reward_type'] = array('in','3,4,5,11');
        $FinanceMothMap['reward_type'] = array('gt','10');
        $FinanceMothMap['type'] = 4;
        $FinanceMoth = Db::name('finance')->where($FinanceMothMap)->sum('num');
        $this->assign('FinanceMoth',$FinanceMoth);

        //总计奖金
//        $TotalFinanceMap['reward_type'] = array('in','1,3,4,5,11');
        $TotalFinanceMap['reward_type'] = array('gt','10');
        $TotalFinanceMap['type'] = 4;
        $TotalFinanceMap['user_id'] = array('neq','1');
        $TotalFinance = Db::name('finance')->where($TotalFinanceMap)->sum('num');
        $this->assign('TotalFinance',$TotalFinance);

        //总计炁点
        $TotalQidianMap['reward_type'] = array('in','1,3,4,5,11');
        $TotalQidianMap['type'] = 2;
        $TotalQidian = Db::name('finance')->where($TotalQidianMap)->sum('num');
        $this->assign('TotalQidian',$TotalQidian);

        //总计电子钱包
//        $TotalQianBaoMap['reward_type'] = array('in','1,3,4,5,11');
//        $TotalQianBaoMap['type'] = 4;
//        $TotalQianBao = Db::name('finance')->where($TotalQianBaoMap)->sum('num');
//        $this->assign('TotalQianBao',$TotalQianBao);

        //余额
        $TotalQianBao = Db::name('user')->where(['id'=>['<>',1]])->sum('balance_4');
        $this->assign('TotalQianBao',$TotalQianBao);
        //总计股权
        $TotalGuQuanMap['reward_type'] = array('in','1,3,4,5,11');
        $TotalGuQuanMap['type'] = 3;
        $TotalGuQuan = Db::name('finance')->where($TotalGuQuanMap)->sum('num');
        $this->assign('TotalGuQuan',$TotalGuQuan);

        //待处理提现
        $Withdraw = WithdrawCount(['status'=>0]);
        $this->assign('Withdraw',$Withdraw);

        //昨日提现金额
        $WithdrawYesterdayMap['sure_time'] = array(array('egt',$BeginYesterday),array('lt',$EndYesterday));
        $WithdrawYesterdayMap['status'] = 1;
        $WithdrawYesterday = Db::name('user_withdraw')->where($WithdrawYesterdayMap)->sum('num');
        $this->assign('WithdrawYesterday',$WithdrawYesterday);

        //本月提现金额
        $WithdrawMothMap['sure_time'] =  array(array('egt',$BeginThismonth),array('elt',$EndThismonth));
        $WithdrawMothMap['status'] =  1;
        $WithdrawMoth = Db::name('user_withdraw')->where($WithdrawMothMap)->sum('num');
        $this->assign('WithdrawMoth',$WithdrawMoth);


        //总提现金额
        $WithdrawTotalMap['status'] = 1;
        $WithdrawTotal = Db::name('user_withdraw')->where($WithdrawTotalMap)->sum('num');
        $this->assign('WithdrawTotal',$WithdrawTotal);

        //支出收入比例
        if($TotalIncome == 0){
            $Proportion = 0;
        }else{
            $Proportion = round($TotalFinance / $TotalIncome,4) * 100;
        }
        $this->assign('Proportion',$Proportion);
        // var_dump($TotalFinance);
        // var_dump($TotalIncome);die;
        // var_dump($Proportion);die;
        //系统参数
        $Config = Config();
        $this->assign('Config',$Config);

        $hhr = Db::name('user')->where(['level'=>8])->count();
        $this->assign('hhr',$hhr);
        //县代人数
        $xian = Db::name('user')->where(['level'=>5])->count();
        $this->assign('xian',$xian);
        //shidai
        $shi = Db::name('user')->where(['level'=>6])->count();
        $this->assign('shi',$shi);
        //sheng
        $sheng = Db::name('user')->where(['level'=>7])->count();
        $this->assign('sheng',$sheng);
        //店铺
        $dian = Db::name('user')->where(['level'=>4])->count();
        $this->assign('dian',$dian);
        $dl = Db::name('user')->where(['level'=>3])->count();
        $this->assign('dl',$dl);
        
        //余额
        $Totalyu = Db::name('user')->where(['id'=>['<>',1]])->sum('balance_4');
        $this->assign('Totalyu',$Totalyu);
        
        //积分
        $Totalji = Db::name('user')->where(['id'=>['<>',1]])->sum('balance_1');
        $this->assign('Totalji',$Totalji);
        
        
        return $this->fetch('Index');
    }
}